use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of Struct yata::indicators::MoneyFlowIndex

/// 参见 [MFI](https://en.wikipedia.org/wiki/Money_flow_index)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct MFI {
    /// 2 signals
    /// When MFI value crosses lower bound downwards, returns full buy signal.
    /// When MFI value crosses upper bound upwards, returns full sell signal.
    /// Otherwise returns no signal.
    pub signal0: Option<IndicatorActionWrap>,
    /// When MFI value crosses lower bound upwards, returns full buy signal.
    /// When MFI value crosses upper bound downwards, returns full sell signal.
    /// Otherwise returns no signal.
    pub signal1: Option<IndicatorActionWrap>,

    ///upper bound const value
    ///Range in [0.5; 1.0]
    pub upper: ValueType,
    ///
    ///MFI value
    ///Range in [0.0; 1.0]
    pub mfi: ValueType,
    ///
    ///lower bound const value
    ///Range in [0.0; 0.5]
    pub lower: ValueType,
}

/// Configuration
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct MFIConfig {
    ///period: PeriodType
    ///Main period size. Default is 14.
    ///
    ///Range is [2; PeriodType::MAX).
    ///
    pub period: PeriodType,
    ///zone: ValueType
    ///Signal zone size. Default is 0.2.
    ///
    ///Range is [0.0; 0.5]. Value 0.5 means that the lower bound is the same as the upper bound.
    pub zone: ValueType,
}

impl Default for MFIConfig {
    fn default() -> Self {
        Self {
            period: 14,
            zone: 0.2,
        }
    }
}
